import Vue from 'vue';
import MyDialog from "@/components/dialog/MyDialog.vue";

function getDialogConstructor(dlgProps, onOkClick, onCancelClick) {
    return Vue.extend({
        render(createElement) {
            return createElement(
              MyDialog, {
                  props: {
                      ...dlgProps,
                      handleOk: onOkClick,
                      handleCancel: onCancelClick
                  }
              }
            )
        }
    })
}

export const useDialog = (dlgProps, onOkClick, onCancelClick) => {
    let DialogConstructor = getDialogConstructor(dlgProps, onOkClick, onCancelClick);
    const instance = new DialogConstructor().$mount();
    document.body.appendChild(instance.$el);
}




